<?php
namespace app\appadmin\controller\v1;
use app\app\Appbase;

class Goods extends Appbase 
{	
	
	/**
	*获取商品分类
	* /appadmin/v1/goods/getGoodsCate
	* 需要登录 
	* @is_need_login true
	*/
	public function getGoodsCate(){
		try {
			$result =  model('GoodsCate')->getList(request()->shopId,'*');
			return $this->ReSucess($result);	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	/**
	*获取商品列表
	* /appadmin/v1/goods/getList
	* 需要登录 
	* @is_need_login true
	*/
	public function getList($name='',$cateid='',$shop_id=0){
		try {
			$model = model('Goods')->setShop($shop_id)->getModel();
			if( !$shop_id ){
				$model = $model->where('type','in',"1,2");
			}
			$cateid && $model = $model->where('a.cate_id',$cateid);
			$name && $model = $model->where('a.name','like',"%".$name."%");
			$result = $model->select();
			return $this->ReSucess($result);	
		} catch (\Exception $e) {
			throw new \think\Exception( $e );
		}
	}
	
	
	
	/**
	*获取商品列表
	* /appadmin/v1/goods/stockList
	* 需要登录 
	* @is_need_login true
	*/
	public function stockList($name='',$cateid='',$shop_id=0){
		try {
			$model = model('Goods')->setShop($shop_id)->getModel();
			$cateid && $model = $model->where('a.cate_id',$cateid);
			$name && $model = $model->where('a.name','like',"%".$name."%");
			$result = $model->select();
			return $this->ReSucess($result);	
		} catch (\Exception $e) {
			throw new \think\Exception( $e );
		}
	}
	
}



